window.addEventListener('load', function () {





    let name1 = document.getElementById('name');
    let paw1 = document.getElementById('password');
    let zc = document.getElementById('zc');
    let tel = document.getElementById('tel');
    let x = null;



    // 判手机号定+密码+用户名
    let yz = function yanZheng() {

        var re = /^1\d{10}$/   /* 手机号正则表达式 */
        var uPattern = /^[a-zA-Z0-9_-]{6,20}$/;   /* 用户名正则表达式 */
        var passWord = /^[\w]{6,12}$/;          /* 密码正则表达式 */

        // 电话号码判定
        if (tel.value == '') {
            tel.style.border = '1px solid black';
        }
        else if (re.test(tel.value)) {
            tel.style.border = '2px solid green';

        } else {
            tel.style.border = '2px solid red';
        }

        // 用户名判定
        if (name1.value == '') {
            name1.style.border = '1px solid black';
        }
        else if (uPattern.test(name1.value)) {
            name1.style.border = '2px solid green';

        } else {
            name1.style.border = '2px solid red';
        }


        // 密码判定
        if (paw1.value == '') {
            paw1.style.border = '1px solid black';
        }
        else if (passWord.test(paw1.value)) {
            paw1.style.border = '2px solid green';
        }
        else {
            paw1.style.border = '2px solid  red';
        }
    }
    this.setInterval(yz, 10);



    let yzmtxt = document.getElementById('yzmtxt');
    let yzm = document.getElementById('yzm');



    // 60s内不能再次获取
    let time = 3;
    function daojishi() {
        if (time == 0) {
            yzm.innerHTML = '重新获取验证码';
            yzm.removeAttribute("disabled");
            return time=3
        }
        else {
            yzm.setAttribute("disabled", true);
            yzm.innerHTML = time + 's'; time--;
        }
        setTimeout(function () {
            daojishi()
        }, 1000)
    }


    // 获取验证码
    yzm.addEventListener('click', function () {
        
        x = parseInt(((Math.random() * 9 + 1) * 100000))
        alert(x);
        daojishi();
        return x;


    })



    // 验证码的判定
    zc.addEventListener('click', function () {

        if (yzmtxt.value == x ) {
            alert('注册成功')
            window.location = 'login.html'

        }
        else {
            alert('验证码错误')
        }



    })





































})